//
//  FavoriteListController.m
//  easystudy
//
//  Created by kane on 16/8/30.
//  Copyright © 2016年 kane. All rights reserved.
//

#import "FavoriteListController.h"
#import "MJRefresh.h"

@interface FavoriteListController ()<UITableViewDataSource,UITableViewDelegate,MJRefreshBaseViewDelegate>
{
    IBOutlet UITableView *dataTable;
    NSMutableArray *dataList;
    NSInteger curIndex;
    MJRefreshHeaderView *header;
}

@end

@implementation FavoriteListController

- (void)viewDidLoad {
    [super viewDidLoad];
    dataList = [NSMutableArray array];
    [self initRefreshUI];
    curIndex = 0;
    [header beginRefreshing];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [header beginRefreshing];
}


- (void)initRefreshUI
{
    header = [MJRefreshHeaderView header];
    header.scrollView = dataTable;
    header.delegate = self;
}

- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    NSDictionary *param = @{@"type":curIndex == 0? @"1":@"2",@"srcId":@"0"};
//    [WebService findFavoriteList:param WithBlock:^(id result, NSError *error) {
//        if (!error) {
//            [dataList removeAllObjects];
//            [dataList addObjectsFromArray:result[@"data"][@"collect"]];
//            [dataTable reloadData];
//        }
//        [refreshView endRefreshing];
//    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)segmentChanged:(UISegmentedControl *)sender
{
    curIndex = sender.selectedSegmentIndex;
    [header beginRefreshing];
}


#pragma mark - Navigation
- (IBAction)backBtnPressed:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableView DataSource && Delegate

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return curIndex == 0 ? 100 : 235;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if (curIndex == 0) {
//        static NSString *identifier = @"HomeClassCell";
//        HomeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//        if (!cell) {
//            [tableView registerNib:[UINib nibWithNibName:@"HomeCell" bundle:nil] forCellReuseIdentifier:identifier];
//            cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        }
//        NSDictionary *item = dataList[indexPath.row];
////        NSString *url = item[@"logo"] && [item[@"logo"] isKindOfClass:[NSString class]] ? item[@"logo"]  : @"";
////        [cell.logoIV setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"home_placeholder"]];
////        cell.nameLbl.text = item[@"name"];
////        cell.addressLbl.text = item[@"address"];
////        cell.addressLbl.numberOfLines = 2;
////        [cell.addressLbl sizeToFit];
//        return cell;
//
//    }else if(curIndex == 1){
//        static NSString *identifier = @"ActivityCell";
//        ActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//        if (!cell) {
//            [tableView registerNib:[UINib nibWithNibName:@"ActivityCell" bundle:nil] forCellReuseIdentifier:identifier];
//            cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        }
//        NSDictionary *item = dataList[indexPath.row];
//        NSString *url = item[@"coverimg"] && [item[@"coverimg"] isKindOfClass:[NSString class]] ? item[@"coverimg"]  : @"";
//        [cell.imgView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"defaultHospital"]];
//        cell.subjectLabel.text = item[@"title"];
//        cell.descLabel.text = item[@"content"];
//        return cell;
//    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (curIndex == 0) {
        NSDictionary *item = dataList[indexPath.row];
//        CourseDetailController *detailVC = [[CourseDetailController alloc] init];
//        detailVC.dataInfo = item;
//        detailVC.hospitalID = [NSString stringWithFormat:@"%@",item[@"cid"]];
//        [self.navigationController pushViewController:detailVC animated:YES];
        
    }else if(curIndex == 1){
//        NSDictionary *item = dataList[indexPath.row];
//        ArticleDetailController *detailVC = [[ArticleDetailController alloc] init];
//        detailVC.dataInfo = item;
//        detailVC.artID = item[@"artid"];
//        [self.navigationController pushViewController:detailVC animated:YES];
    }
}

@end
